/*
 * @Author: 陈明烽
 * @FilePath: /evdata/src/PageViewNew/index.tsx
 * @Description: 为了适应新的样式，比如系统名称在头部
 */
import * as React from 'react';
import { useMemo } from 'react';
import { Breadcrumb } from 'antd';
import { Link } from 'react-router-dom';
import classnames from 'classnames';
export interface LinkRrouter {
  name: string;
  address?: string;
}

export interface PageViewProps {
  /** 面包屑数组  */
  linkRrouters?: LinkRrouter[];
  /** 顶部padding */
  paddingTop?: number;
  /** 底部padding */
  paddingBottom?: number;
  /** 是否显示面包屑 */
  isShowCrumb?: boolean;
}

const PageViewNew: React.FC<PageViewProps> = props => {
  const {
    linkRrouters,
    children,
    paddingTop,
    paddingBottom,
    isShowCrumb,
  } = props;
  // const styles = {
  //   paddingTop: paddingTop + 'px',
  //   paddingBottom: paddingBottom + 'px',
  // };
  const styles = useMemo(() => {
    return {
      paddingTop: paddingTop + 'px',
      paddingBottom: paddingBottom + 'px',
    };
  }, [paddingTop, paddingBottom]);
  const crumbClassName = classnames('c-page-view-new-crumb');
  return (
    <div className="c-page-view-new" style={styles}>
      {isShowCrumb && (
        <div className="c-page-view-new-crumb">
          <Breadcrumb>

            {linkRrouters && linkRrouters.length > 0
              ? [
                  linkRrouters.map((v, i) => {
                    return (
                      <Breadcrumb.Item key={i}>
                        {/* {v.address?(<Link to={v.address}>{v.name}</Link>) } */}
                        {v.address ? (
                          <Link to={v.address}>{v.name}</Link>
                        ) : (
                          <span>{v.name}</span>
                        )}
                      </Breadcrumb.Item>
                    );
                  }),
                ]
              : null}
          </Breadcrumb>
        </div>
      )}

      {children}
    </div>
  );
};
PageViewNew.defaultProps = {
  linkRrouters: [],
  paddingTop: 20,
  paddingBottom: 20,
  isShowCrumb: true,
};

export default PageViewNew;
